package JDK8;

import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Stream {
    public static void main(String[] args) {
        System.out.println("-----一、Lambda表达式----------");
        System.out.println("------二、stream--------");
        System.out.println("---------1、filter:(参数 -> 方法)----forEach-----");
        List<String> strings = Arrays.asList("a","b","","d","e","");
        //第一种
        strings.stream().filter((x -> x!= "")).forEach(System.out::println);
        //第二种
        System.out.println("collect(Cllectors.toList())");
        List<String> stringList = strings.stream().filter((x -> x!="")).collect(Collectors.toList());
        for(String str: stringList){
            System.out.println(str);
        }

        System.out.println("\n");
        System.out.println("-----------2、sorted-----排序");
        List<Integer> ints = Arrays.asList(1,7,6,3,5,4,2,9,8);
        System.out.println("排序");
        ints.stream().sorted().forEach(System.out::println);
        System.out.println("无排序");
        ints.forEach((x) -> System.out.println(x));

        System.out.println("\n");
        System.out.println("-------3、IntStream  Random.ints(0,100) 随机0-100整数-----");
        Random random = new Random();
        IntStream intStream = random.ints();
        System.out.println(intStream.limit(3));
        random.ints(0,10).limit(3).forEach(System.out::println);

        System.out.println("\n");
        System.out.println("-------4、distinct():去重--------");
        List<Integer> integerList = Arrays.asList(0,1,1,1,2,2,4,3,2,3,4,5,5,6,6);
        integerList.stream().distinct().forEach(System.out::println);
    }
}
